/** <a href="http://www.cpupk.com/decompiler">Eclipse Class Decompiler</a> plugin, Copyright (c) 2017 Chen Chao. **/
package com.minierp.view;

import com.minierp.bean.AccountBalanceBean;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.Region;
import org.springframework.web.servlet.view.document.AbstractExcelView;

public class AccountBalanceListExcelView extends AbstractExcelView {
	public void buildExcelDocument(Map model, HSSFWorkbook workbook,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		response.reset();
		response.setContentType("APPLICATION/vnd.ms-excel");
		response.setHeader("Content-Disposition",
				"attachment;filename=\"AccountBalanceList.xls\"");
		HSSFFont font = workbook.createFont();
		font.setFontHeightInPoints(10);
		font.setColor(10);
		font.setFontName("黑体");
		font.setBoldweight(700);
		HSSFCellStyle cellStyle = workbook.createCellStyle();
		cellStyle.setFont(font);
		cellStyle.setAlignment(2);
		cellStyle.setBorderBottom(1);
		cellStyle.setWrapText(true);
		cellStyle.setFillForegroundColor(22);
		cellStyle.setFillPattern(1);
		HSSFSheet sheet = workbook.createSheet("list");
		HSSFRow r = sheet.createRow(0);
		HSSFCell c = r.createCell(0);
		r.createCell(1);
		r.createCell(2);
		r.createCell(3);
		r.createCell(4);
		r.createCell(5);
		r.createCell(6);
		r.createCell(7);
		r.createCell(8);
		r.createCell(9);
		r.createCell(10);
		r.createCell(11);
		r.createCell(12);
		r.createCell(13);
		r.createCell(14);
		c.setCellValue(new HSSFRichTextString("现金银行（"
				+ model.get("startDate").toString() + " 至 "
				+ model.get("endDate").toString() + "）"));
		sheet.addMergedRegion(new Region(0, 0, 0, 14));
		r = sheet.createRow(1);
		r.createCell(0).setCellValue(new HSSFRichTextString("账户名称"));
		r.createCell(1).setCellValue(new HSSFRichTextString("期初余额（元）"));
		r.createCell(2).setCellValue(new HSSFRichTextString("收入（元）"));
		r.createCell(3);
		r.createCell(4);
		r.createCell(5);
		r.createCell(6);
		r.createCell(7).setCellValue(new HSSFRichTextString("支出（元）"));
		r.createCell(8);
		r.createCell(9);
		r.createCell(10);
		r.createCell(11);
		r.createCell(12);
		r.createCell(13).setCellValue(new HSSFRichTextString("期末余额"));
		r.createCell(14).setCellValue(new HSSFRichTextString("增加额"));
		r = sheet.createRow(2);
		r.createCell(0);
		r.createCell(1);
		r.createCell(2).setCellValue(new HSSFRichTextString("业务"));
		r.createCell(3).setCellValue(new HSSFRichTextString("其他"));
		r.createCell(4).setCellValue(new HSSFRichTextString("借入"));
		r.createCell(5).setCellValue(new HSSFRichTextString("转入"));
		r.createCell(6).setCellValue(new HSSFRichTextString("小计"));
		r.createCell(7).setCellValue(new HSSFRichTextString("采购"));
		r.createCell(8).setCellValue(new HSSFRichTextString("外协"));
		r.createCell(9).setCellValue(new HSSFRichTextString("费用"));
		r.createCell(10).setCellValue(new HSSFRichTextString("借出"));
		r.createCell(11).setCellValue(new HSSFRichTextString("转出"));
		r.createCell(12).setCellValue(new HSSFRichTextString("小计"));
		r.createCell(13);
		r.createCell(14);
		sheet.addMergedRegion(new Region(1, 0, 2, 0));
		sheet.addMergedRegion(new Region(1, 1, 2, 1));
		sheet.addMergedRegion(new Region(1, 2, 1, 6));
		sheet.addMergedRegion(new Region(1, 7, 1, 12));
		sheet.addMergedRegion(new Region(1, 13, 2, 13));
		sheet.addMergedRegion(new Region(1, 14, 2, 14));
		List list = (List) model.get("list");
		boolean i = false;

		AccountBalanceBean totalBean;
		int arg13;
		for (arg13 = 0; arg13 < list.size(); ++arg13) {
			totalBean = (AccountBalanceBean) list.get(arg13);
			r = sheet.createRow(arg13 + 3);
			r.createCell(0).setCellValue(
					new HSSFRichTextString(totalBean.getAccountName()));
			r.createCell(1)
					.setCellValue(totalBean.getStartCost().doubleValue());
			r.createCell(2).setCellValue(totalBean.getBusCost().doubleValue());
			r.createCell(3).setCellValue(
					totalBean.getIncomeCost().doubleValue());
			r.createCell(4).setCellValue(
					totalBean.getLoanInCost().doubleValue());
			r.createCell(5).setCellValue(
					totalBean.getTranInCost().doubleValue());
			r.createCell(6).setCellValue(totalBean.getRecCost().doubleValue());
			r.createCell(7).setCellValue(totalBean.getPurCost().doubleValue());
			r.createCell(8).setCellValue(totalBean.getCooCost().doubleValue());
			r.createCell(9).setCellValue(totalBean.getFeeCost().doubleValue());
			r.createCell(10).setCellValue(
					totalBean.getLoanOutCost().doubleValue());
			r.createCell(11).setCellValue(
					totalBean.getTranOutCost().doubleValue());
			r.createCell(12).setCellValue(totalBean.getExpCost().doubleValue());
			r.createCell(13).setCellValue(totalBean.getEndCost().doubleValue());
			r.createCell(14).setCellValue(
					totalBean.getRecCost().subtract(totalBean.getExpCost())
							.doubleValue());
		}

		totalBean = (AccountBalanceBean) model.get("totalBean");
		r = sheet.createRow(arg13 + 3);
		r.createCell(0).setCellValue(new HSSFRichTextString("合计"));
		r.createCell(1).setCellValue(totalBean.getStartCost().doubleValue());
		r.createCell(2).setCellValue(totalBean.getBusCost().doubleValue());
		r.createCell(3).setCellValue(totalBean.getIncomeCost().doubleValue());
		r.createCell(4).setCellValue(totalBean.getLoanInCost().doubleValue());
		r.createCell(5).setCellValue(totalBean.getTranInCost().doubleValue());
		r.createCell(6).setCellValue(totalBean.getRecCost().doubleValue());
		r.createCell(7).setCellValue(totalBean.getPurCost().doubleValue());
		r.createCell(8).setCellValue(totalBean.getCooCost().doubleValue());
		r.createCell(9).setCellValue(totalBean.getFeeCost().doubleValue());
		r.createCell(10).setCellValue(totalBean.getLoanOutCost().doubleValue());
		r.createCell(11).setCellValue(totalBean.getTranOutCost().doubleValue());
		r.createCell(12).setCellValue(totalBean.getExpCost().doubleValue());
		r.createCell(13).setCellValue(totalBean.getEndCost().doubleValue());
		r.createCell(14).setCellValue(
				totalBean.getRecCost().subtract(totalBean.getExpCost())
						.doubleValue());
		ServletOutputStream os = response.getOutputStream();
		workbook.write(os);
		os.flush();
		os.close();
	}
}